import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
public class PersonAdvice {
    public void before(){
        System.out.println("前置通知");
    }

    public void after(){
        System.out.println("后置通知");
    }
    public void afterReturning(){
        System.out.println("返回通知");
    }
    public void afterThrowing(){
        System.out.println("异常通知");
    }

    /**
     * 环绕通知：可代替上面四个
     * @param proceedingJoinPoint
     */
    public void around(ProceedingJoinPoint proceedingJoinPoint){
        String methodName = proceedingJoinPoint.getSignature().getName();
        System.out.println("环绕通知-前置通知："+methodName);
        try {
            // 表示调用真实的方法
            Object obj = proceedingJoinPoint.proceed();
            System.out.println("环绕通知-返回通知："+methodName+" 返回结果：" + obj.toString());
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("环绕通知-异常通知："+methodName);
        } finally {
            System.out.println("环绕通知-后置通知："+methodName);
        }

    }
}
